﻿﻿
<!--********************* Part1:Jsp Head *********************-->

<%@ page contentType="text/html;charset=UTF-8"%>  
<%@ include file="/framework/head.jsp"%>

<!--********************* Part2:Java Code *********************-->
<%
    //new code line 1 (benny)
    system.LoginContext lc = (system.LoginContext)context.getSessionValue("LoginContext");
	CustomerPageData obj = (CustomerPageData)context.getValue("CustomerPageData");
    Customer com = (Customer)context.getValue("UpperCustomer");
    if (com == null) com = new Customer();
%>

<!--********************* Part3:JavaScript Code ***************-->
<script language="javascript">
var g_check_items = new Array();
var g_i = 0 ;
//g_check_items[g_i++] = new CheckItem("上级客户","UpperCustomerCode",false,true,20,false,0);
//g_check_items[g_i++] = new CheckItem("默认配送仓库","WarehouseCode",false,true,20,false,0);

//g_check_items[g_i++] = new CheckItem("编码","Code1",true,true,2,false,0);

g_check_items[g_i++] = new CheckItem("自编码","SelfCode",false,true,20,false,0);

g_check_items[g_i++] = new CheckItem("名称","Name",true,true,50,false,0);

g_check_items[g_i++] = new CheckItem("全称","FullName",true,true,200,false,0);

g_check_items[g_i++] = new CheckItem("地址","Address",false,true,500,false,0);

g_check_items[g_i++] = new CheckItem("联系人","ContactPerson",false,true,20,false,0);

g_check_items[g_i++] = new CheckItem("联系电话","ContactTel",false,true,20,false,0);

//g_check_items[g_i++] = new CheckItem("是否结算单位","IsBalance",true,true,1,false,0);

//g_check_items[g_i++] = new CheckItem("是否领料单位","IsDraw",true,true,1,false,0);

//g_check_items[g_i++] = new CheckItem("是否有效","Status",false,true,1,false,0);

g_check_items[g_i++] = new CheckItem("备注","Remark",false,true,500,false,0);

function chk(){
    var obj = document.getElementById("Code1");
    if(obj.value <= 0){
        alert("编号应大于零");
        return false;
    }else{
        return true;
    }
}
//保存并添加按钮激发事件
function doSaveAndNew(){
    //判断状态是否可交互 true:不可交互 即:非添加状态
    var codeObject = document.getElementById("Code1");
    var result = codeObject.isDisabled;   
    var bennyValue = GetString("UpperCustomerCode",null)+GetString("Code1",null);
    //修改状态
    if(result){
        SetValue("Code",GetString("Code1",null));
        if(!CheckInput(g_check_items)) return false;
        SetAction("saveAndNewCustomer");
        frm.submit();
    }else{
        //非修改.可输入状态
        var chkResult = chk();//编号应大于零判断 true:满足条件
        if(chkResult){
            var length = GetValue("Code1").length ;
            if (length != 2){
                alert("编码必须为两位!");
                focusAndSelect("Code1");
                return false;         
            }else{
                if(!CheckInput(g_check_items)) {
                    return false;
                }else{
                    //进行编码设值
                    SetValue("Code",bennyValue);
                    SetAction("saveAndNewCustomer");
                    frm.submit();
                }
            }
        }else{//输入编码小于零.不符合要求跳出
            return false;
        }
    }
}
//保存按钮激发事件
function doSave(){
    //判断状态是否可交互 true:不可交互 即:非添加状态
    var codeObject = document.getElementById("Code1");
    var result = codeObject.isDisabled;   
    var bennyValue = GetString("UpperCustomerCode",null)+GetString("Code1",null);
    //修改状态
    if(result){
        SetValue("Code",GetString("Code1",null));
        if(!CheckInput(g_check_items)) return false;
        SetAction("saveCustomer");
        frm.submit();
    }else{
        //非修改.可输入状态
        var chkResult = chk();//编号应大于零判断 true:满足条件
        if(chkResult){
            var length = GetValue("Code1").length ;
            if (length != 2){
                alert("编码必须为两位!");
                focusAndSelect("Code1");
                return false;         
            }else{
                if(!CheckInput(g_check_items)) {
                    return false;
                }else{
                    //进行编码设值
                    SetValue("Code",bennyValue);
                    SetAction("saveCustomer");
                    frm.submit();    
                }
            }
        }else{//输入编码小于零.不符合要求跳出
            return false;
        }
    }
}

function doCancel()
{
	SetAction("backListCustomer");
	frm.submit();
}

key_InitDefault();
key_RegSubmitHandler(doSaveAndNew);
</script>

<%=uiBody%>>

<%@ include file="/framework/menu.jsp"%>

<!--********************* Part4:Form  ***************-->

<form id=frm action="<%=Config.getSrv()%>" method="post">
<input type=hidden name="action_code">

<input type=hidden name="Id" value="<%=obj.getId()%>">


<br>

<%=UIManager.addEditHeadTitle("客户管理")%>


<!--********************* Part5:Edit Area  ***************-->
<%=uiEditStart%>>
<%
	int key_tab = 1 ;
%>

	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>上级客户：</td>
		<%=uiEditTD%>><%=com!=null? com.viewName(con):com.viewCode(con)%>
			<input type=hidden class="texts"  name="UpperCustomerCode" size=20  value="<%=com!=null?com.viewCode(con):""%>" key_tab="<%=key_tab++%>">
            <input type=hidden class="texts"  name="UpperCustomerId" size=20  value="<%=com!=null ? com.viewId(con):""%>" key_tab="<%=key_tab++%>">
		</td>
	</tr>
    
	<%=uiEditTR%>>
        <%=uiEditHeadTD%> width=250>默认配送仓库：</td>
        <%=uiEditTD%>><%=lc.getLoginWarehouseName()%>
            <input type=hidden class="texts"  name="WarehouseCode" size=20  value="<%=lc.getLoginWarehouseCode()%>" key_tab="<%=key_tab++%>">
            <input type=hidden class="texts"  name="WarehouseName" size=20  value="<%=lc.getLoginWarehouseName()%>" key_tab="<%=key_tab++%>">
        </td>
    </tr>
    
    <%=uiEditTR%>>
        <%=uiEditHeadTD%> width=250>编码：</td>
        <%=uiEditTD%>>
        <% if (obj.viewCode(con).hashCode()==0) { %>
            <%if(com!=null){%>
            <script language="javascript">bennyValue = <%com.viewCode(con); %>;alert(bennyValue+"174");</script>
            <%=com.viewCode(con) %><%}%><input type=text class="texts" id="Code1"  name="Code1" size=10 value="<%=obj.viewCode(con) %>"><font color=red>*</font>
            
        <% } else { %>
            <input type=text class="texts" id="Code1" name="Code1" size=20  value=<%=obj.getCode() %> key_tab="<%=key_tab++%>" disabled><font color=red>*</font>
        <% } %>
            <input type=hidden class="texts"  name="Code" size=10  value="" key_tab="<%=key_tab++%>">
        </td>
    </tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>自编码：</td>
		<%=uiEditTD%>>
			<input type=text class="texts"  name="SelfCode" size=20  value="<%=obj.viewSelfCode(con)%>" key_tab="<%=key_tab++%>">
		</td>
	</tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>名称：</td>
		<%=uiEditTD%>>
			<input type=text class="texts"  name="Name" size=20  value="<%=obj.viewName(con)%>" key_tab="<%=key_tab++%>"><font color=red>*</font>
		</td>
	</tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>全称：</td>
		<%=uiEditTD%>>
			<input type=text class="texts"  name="FullName" size=20  value="<%=obj.viewFullName(con)%>" key_tab="<%=key_tab++%>"><font color=red>*</font>
		</td>
	</tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>地址：</td>
		<%=uiEditTD%>>
			<input type=text class="texts"  name="Address" size=20  value="<%=obj.viewAddress(con)%>" key_tab="<%=key_tab++%>">
		</td>
	</tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>联系人：</td>
		<%=uiEditTD%>>
			<input type=text class="texts"  name="ContactPerson" size=20  value="<%=obj.viewContactPerson(con)%>" key_tab="<%=key_tab++%>">
		</td>
	</tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>联系电话：</td>
		<%=uiEditTD%>>
			<input type=text class="texts"  name="ContactTel" size=20  value="<%=obj.viewContactTel(con)%>" key_tab="<%=key_tab++%>">
		</td>
	</tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>是否结算单位：</td>
		<%=uiEditTD%>>
            <%=SelectManager.viewYesOrNoRadio("IsBalance",obj.viewIsBalance(con), "key_tab="+(key_tab++)) %>
		</td>
	</tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>是否领料单位：</td>
		<%=uiEditTD%>>
            <%=SelectManager.viewYesOrNoRadio("IsDraw",obj.viewIsDraw(con), "key_tab="+(key_tab++)) %>
		</td>
	</tr>
    
    <%=uiEditTR%>>
        <%=uiEditHeadTD%> width=250>有效性：</td>
        <%=uiEditTD%>>
            <%=SelectManager.viewValidOrNoRadio("Status",obj.viewStatus(con), "key_tab="+(key_tab++)) %>
        </td>
    </tr>
	
	<%=uiEditTR%>>
		<%=uiEditHeadTD%> width=250>备注：</td>
		<%=uiEditTD%>>
		    <textarea cols="50" rows="3" name="Remark" key_tab="<%=key_tab++%>"><%=obj.viewRemark(con)%></textarea>
        </td>
	</tr>

<%=uiEditEnd%>

<!--********************* Part6:Action Area  ***************-->
<%=uiCommandStart%>>
	<%=uiCommandTR%>>
   		<%=uiCommandTD%>>                     
			<input type=button class="buttons" value=" 保存&添加 " onclick="doSaveAndNew();return false;">
			<input type=button class="buttons" value="    保存   " onclick="doSave();return false;">
			<input type=button class="buttons" value="    返回   " onclick="doCancel();return false;">
		</td>
	</tr>
<%=uiCommandEnd%>
</form>

<%@ include file="/framework/foot.jsp"%>

<!--
	Author    :Wing
	FileName  :/system/base/CustomerEdit.jsp
-->
